const CronJob = require('cron').CronJob
const fork = require('child_process').fork
const path = require('path')

module.exports = class CronController {
  constructor () {
    this.cronInstance = null
  }
  start () {
    const job = new CronJob('0 0 22 * * *', () => {
      let child = fork(path.resolve(__dirname, './cronPush.js'))
      child.on('exit', code => {
        if (code === 0) {
        }
      })
      child.on('message', message => {
        const { code, data, msg } = message
        if (code === 1) {
          job.stop()
        }
      })
    }, null, false, 'Asia/Shanghai', null)
    this.cronInstance = job
    job.start()
  }
}
